const _ = require('lodash');
const commonService = require('../common');

function getBusinessNodeList(formId, id, callback) {
  const models = commonService.getModels();
  const { WfForm: formModel } = models;
  let businessNodeList = [];
  commonService.getDetail(formModel, { where: { id: formId } }, (error, form) => {
    if (!_.isEmpty(form)) businessNodeList = form.others.businessNode;
    callback(error, businessNodeList);
  });
}

function getTaGroupList(formId, id, callback) {
  const models = commonService.getModels();
  const { SysRole: roleModel } = models;
  const taGroupList = [];
  commonService.getList(roleModel, { where: { type: 'ta' } }, (error, roleList) => {
    _.forEach(roleList, roleItem => taGroupList.push({ key: roleItem.id, value: roleItem.name }));
    callback(error, taGroupList);
  });
}

module.exports = {
  getBusinessNodeList,
  getTaGroupList,
};
